package com.ruoyi.mq.kafka;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.mq.kafka.KafkaMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>className: KafkaProducer</p>
 * <p>description: 消息生产者</p>
 *
 * @author CG
 * @version 1.0.0
 * @date 2019-08-27 09:49
 */
@Service("com.ruoyi.mq.kafka.KafkaProducer")
public class KafkaProducer {
    private static Logger logger = LoggerFactory.getLogger(KafkaProducer.class);

    @Value("${kakfa.mq.topic:openresty-log}")
    private String mqTopic ;
    @Autowired
    private KafkaTemplate<String,String> kafkaTem;

    public void send(String content){
        KafkaMessage msg = new KafkaMessage();
        msg.setId(System.currentTimeMillis());
        msg.setMsg("KakfaMSG test"+content);
        msg.setSendTime(new Date());

        kafkaTem.send(mqTopic, JSONObject.toJSONString(msg));
    }
}